package com.happycat.controller.social;

import cn.hutool.core.util.StrUtil;
import com.happycat.base.R;
import com.happycat.mobile.model.UserAccount;
import com.happycat.social.service.ISocialWxService;
import com.happycat.utils.ObjectsUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author shenbin
 * @CreatedDate 2020-09-14
 * @Modified By:
 */
@RestController
@RequestMapping("/social/login")
@Api(tags = "API-第三方登录", value = "注册登录等功能")
public class SocialLoginController {

    @Autowired
    private ISocialWxService socialWxService;

    @ApiOperation(value = "微信登录", notes = "当前支持小程序登录")
    @ApiImplicitParams({
        @ApiImplicitParam(name="thirdLoginType", value = "第三方登录类型:1:微信小程序登录，2:微信移动应用登录，3:微信h5登录", required = true),
        @ApiImplicitParam(name="raw", value = "微信授权登录信息", required = true)
    })
    @PostMapping(value = "wxLogin")
    public R<UserAccount> wxLogin(@RequestParam(value = "thirdLoginType", required = true) Integer thirdLoginType,
                                  @RequestParam(value="raw", required = true) String raw){
        ObjectsUtil.requireNonNull(thirdLoginType, "第三方登录类型不能为空");
        if(StrUtil.isBlank(raw)){
            return R.fail("授权登录信息不能为空");
        }
        return R.success(socialWxService.wxLogin(thirdLoginType, raw));
    }
}
